package com.sophialex.health.record.dialog;

import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TableColumn;

import com.sophialex.health.person.vo.HrPerson;
import com.sophialex.health.record.Messages;
import com.sophialex.health.record.common.dialog.CommonDlg;
import com.sophialex.health.record.common.util.HealthRecordContants;
import com.sophialex.health.record.lktable.cellstyle.SelectPersonValueConvert;
import com.sophialex.health.system.lktable.LKTable;

public class HrPersonMemberSelectDlg extends CommonDlg {
    private LKTable lktable;
    private Shell shell_parent;
    private HrPerson hrPerson;
	public HrPersonMemberSelectDlg(Shell parent, List list) {
		super(parent);
		this.list = list;
		proStr = new String[] { "name", "sex", "birthday","idno","adminUserId","cadress"}; 
		filterPro = new String[] { "name" }; 
		
	}

	public HrPersonMemberSelectDlg(Shell parent) {
		super(parent);
		proStr = new String[] { "name", "sex", "birthday","idno","adminUserId","cadress"}; 
		filterPro = new String[] { "name" }; 
		
	}
    
	public HrPersonMemberSelectDlg(LKTable lktable,Shell parent, List list,HrPerson hrPerson,int showType) {
		super(parent);
		this.type = showType;
		this.lktable = lktable;
		this.list = list;
		this.shell_parent = parent;
		this.hrPerson = hrPerson;
		proStr = new String[] { "name", "sex", "birthday","idno","adminUserId","cadress"}; 
		filterPro = new String[] { "name" }; 
		
	}
	
	public HrPersonMemberSelectDlg(LKTable lktable,Shell parent, List list,HrPerson hrPerson) {
		super(parent);
		this.type = HealthRecordContants.SHOW_ADD_PERSON_DIALOG_TYPE;
		this.lktable = lktable;
		this.list = list;
		this.shell_parent = parent;
		this.hrPerson = hrPerson;
		proStr = new String[] { "name", "sex", "birthday","idno","adminUserId","cadress"}; 
		filterPro = new String[] { "name" }; 
	}
	
	@Override
	protected void createColumn() {
		{
			TableColumn column = new TableColumn(table, SWT.NONE);
			column.setText(Messages.getString("HrPersonAssist.0")); 
			column.setWidth(80);
		}
		{
			TableColumn column = new TableColumn(table, SWT.NONE);
			column.setText(Messages.getString("HrPersonAssist.1")); 
			column.setWidth(80);
		}
		{
			TableColumn column = new TableColumn(table, SWT.NONE);
			column.setText(Messages.getString("HrPersonAssist.2")); 
			column.setWidth(100);
		}
		{
			TableColumn column = new TableColumn(table, SWT.NONE);
			column.setText(Messages.getString("HrPersonAssist.3")); 
			column.setWidth(120);
		}
		{
			TableColumn column = new TableColumn(table, SWT.NONE);
			column.setText(Messages.getString("HrPersonAssist.4")); 
			column.setWidth(100);
		}
		{
			TableColumn column = new TableColumn(table, SWT.NONE);
			column.setText(Messages.getString("HrPersonAssist.5")); 
			column.setWidth(200);
		}
		dbTable.setColumnProperties(proStr);
		dbTable.exeDbTable(HrPerson.class);
		dbTable.setJoinOutFild("@adminUserId", "adminUserId", new SelectPersonValueConvert());
		dbTable.setJoinOutFild("@sex", "sex", new SelectPersonValueConvert());
	}

	protected void setSize() {
		shell.setSize(720, 550);
	}


	protected void openDialog() {
		 QuackAddPersonDialog addPersonDialog = new QuackAddPersonDialog(lktable,hrPerson,shell_parent, SWT.NONE);
		 HrPerson t = (HrPerson) addPersonDialog.open();
			if (t != null) {
				 try {
					BeanUtils.copyProperties(hrPerson, t);
				}
				catch(Exception e) {
					e.printStackTrace();
				}
				lktable.redraw();
			}
		
	}
}
